fix(ui): resolve root-relative README markdown links to repo blob URLs#2929
fix(ui): resolve root-relative README markdown links to repo blob URLs#2929BittuBarnwal7479 wants to merge 5 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughSummary by CodeRabbit
Walkthrough
ChangesRoot-relative URL resolution fix
Badge Style dropdown dark-mode styling
Possibly related issues
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
Caution Review failedAn error occurred during the review process. Please try again later. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| const result = await renderReadmeHtml(markdown, 'test-pkg', repoInfo) | ||
|
|
||
| expect(result.html).toContain('href="/package/test-pkg"') | ||
| }) |
There was a problem hiding this comment.
Is there a reason why we want this behaviour for non-markdown links?
Why not something similar to what is done for this?
npmx.dev/test/unit/server/utils/readme.spec.ts
Lines 219 to 227 in 46e7c59
There was a problem hiding this comment.
Good catch. I updated this to resolve root-relative non-markdown links via rawBaseUrl, consistent with existing relative-link handling. Markdown files still resolve via blobBaseUrl.
Local npmx routes (/package, /org, /search, etc.) are preserved separately, and I added regression tests covering both behaviors.
There was a problem hiding this comment.
Is there a reason / place where preserving Local npmx routes would be useful instead of them resolving to rawBaseUrl too?
There was a problem hiding this comment.
yes. the main case is npmjs links that the README renderer intentionally converts to local npmx routes. For example, https://www.npmjs.com/package/test-pkg becomes /package/test-pkg.
If we treated every root-relative path as a repo file, that converted route would incorrectly become rawBaseUrl/package/test-pkg.
So the updated logic preserves known npmx routes separately, while root-relative repo files like /CONTRIBUTING.md and /assets/logo.png resolve to blobBaseUrl / rawBaseUrl.
There was a problem hiding this comment.
Hmm, is there no way to differentiate a /package that was because of https://www.npmjs.com/package/test-pkg from a /package that someone wrote in their readme?
There was a problem hiding this comment.
good point. i will update this to preserve npmjs-originated links via an internal marker rather than path matching. README-authored root-relative paths now resolve normally against the repository. Added regression tests for both cases.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
server/utils/readme.ts (1)
352-358:⚠️ Potential issue | 🟠 Major | ⚡ Quick winKeep protocol-relative URLs out of the root-relative rewrite.
//cdn.example.com/file.cssalso satisfiesurl.startsWith('/'), so with repository info it becomeshttps://raw.githubusercontent.com/.../HEAD//cdn.example.com/file.cssinstead of staying external. The later protocol-relative handling never gets a chance to run.Proposed fix
- if (url.startsWith('/')) { + if (url.startsWith('/') && !url.startsWith('//')) { if (!repoInfo?.rawBaseUrl) { return url } const baseUrl = isMarkdownFile ? repoInfo.blobBaseUrl : repoInfo.rawBaseUrl return `${baseUrl}${url}` }Please add a regression case such as
[CDN](//cdn.example.com/file.css)withrepoInfoand assert the href remains protocol-relative.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@server/utils/readme.ts` around lines 352 - 358, The root-relative URL check at the beginning of the conditional block (url.startsWith('/')) is incorrectly matching protocol-relative URLs that start with //, causing them to be rewritten as repository URLs instead of remaining external. Add an additional condition to explicitly exclude protocol-relative URLs (those starting with //) before processing the root-relative URL case in the repoInfo block. Additionally, add a regression test case that verifies a markdown link with a protocol-relative URL like [CDN](//cdn.example.com/file.css) correctly preserves the protocol-relative href when repoInfo is present.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@server/utils/readme.ts`:
- Around line 352-358: The root-relative URL check at the beginning of the
conditional block (url.startsWith('/')) is incorrectly matching
protocol-relative URLs that start with //, causing them to be rewritten as
repository URLs instead of remaining external. Add an additional condition to
explicitly exclude protocol-relative URLs (those starting with //) before
processing the root-relative URL case in the repoInfo block. Additionally, add a
regression test case that verifies a markdown link with a protocol-relative URL
like [CDN](//cdn.example.com/file.css) correctly preserves the protocol-relative
href when repoInfo is present.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: e84a9795-dd1d-41b7-b64c-33fc7a943e87
📒 Files selected for processing (2)
server/utils/readme.tstest/unit/server/utils/readme.spec.ts
|
@CodeRabbit review again. |
|
✅ Action performedReview finished.
|
🔗 Linked issue
#2928
🧭 Context
Steps to Reproduce
Recording.2026-06-17.174239.mp4
📚 Description
On package readme.ts page, root-relative markdown links such as /CONTRIBUTING.md are resolved as local npmx routes instead of repository files.